
#pragma once
#include <QStandardItemModel>
#include <Qt>
#include <interactive_markers/interactive_marker_server.hpp>
#include <list>

using visualization_msgs::msg::InteractiveMarker;
using interactive_markers::InteractiveMarkerServer;

namespace rviz_custom_plugins
{

namespace viewmodels
{

class InteractiveMarkerModel : public QStandardItemModel {
    Q_OBJECT

public:
    explicit InteractiveMarkerModel(QObject *parent = nullptr) ;

    // 支持编辑：双击单元格修改后同步更新 QVector 中的值
    bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;

    // 设置所有项可编辑
    Qt::ItemFlags flags(const QModelIndex& index) const override;

    bool insertMarker(int row, InteractiveMarker& intMarker);
    void removeMarker(int row);

    void handleMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);

    InteractiveMarker& getRowMarker(int row);
    int getMarkerRow(QString& markerName);

    std::list<InteractiveMarker>& getMarkers();
signals:
    void markerEditUpdated(const InteractiveMarker& marker);
    void markerOrderUpdated(int row, std::list<InteractiveMarker>& markers);

private:
    inline static const QString ROW = "row";
    // 存储真实数据
    std::list<InteractiveMarker> markers;

    void handlePointsReorder(int row);

};

}

}
